home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: wzjn@ix.netcom.com (KPN )
- Newsgroups: comp.lang.c
- Subject: Re: Confusion as to the proper use of MODULAS
- Date: 14 Feb 1996 20:49:34 GMT
- Organization: Netcom
- Message-ID: <4fthsu$1kl@ixnews7.ix.netcom.com>
- References: <4fr8be$ass@news.iconn.net> <31224679.6193@born.com>
- NNTP-Posting-Host: ix-frm-ma1-03.ix.netcom.com
- X-NETCOM-Date: Wed Feb 14 12:49:34 PM PST 1996
-
- Confusion as to the proper use of MODULAS
-
- Very confused. Just as I think IÆve got it correct, I make-up a new
- test, the results of which leave me mixed-up again.
-
- To begin with, this is the first rule I found out:
-
- Modulas operator simply shows: *** AFTER *** you divide, what is the
- remainder?
- EXAMPLE of this:
- 9 % 7 = ?
- 9 divided by 7 yields a remainder of 2
- 9 % 7 = 2
-
- 1) MODULAS means divide a number and give me the left over number. OK -
- not bad.
-
- Next rule:
- If the number to be divided is smaller than the number to divide by,
- the result will always be the number being divided
- EXAMPLE of this:
-
- 9 % 12 = ?
- can not divide 9 by a larger number
- 9 % 12 = 9
- Now I have rule #2
-
- 2) If the number to be divided is smaller than the nuber to be used as
- a divisor, the result is the original number. OK - again, not bad.
-
- Here, begin my troubles: using MODULAS in an IF statement.
-
- I made up a test to see if a number I inputted was a 7. Sample code:
-
- if (number % 7)
- printf("Not a 7\n");
- else
- printf("First integer was a 7\n");
-
- So, if the number WAS a 7, the ELSE would take over. OK. But, when I
- enter in a ZERO, it still tells me that the number was a seven?
-
- Am I going in the right direction? Can someone tell me what IÆm doing
- incorrectly, or where IÆm straying? WhatÆs the rule here for using MOD
- in an IF statement?
-
- Thank you for your help,
- kevin
-
-
-
- "When their numbers dwindled from 50 down to 8, the remaining dwarfs
- began to suspect 'Hungry'."
-
-
-
-
-
-